let gl = null;
function getGLContext() {
    let canvas = document.getElementById('canvas-element-id');
    if (canvas === null) {
        alert('there is no canvas on this page');
        return;
    }
    let names = [
        'webgl',
        'experimental-webgl',
        'moz-webgl'
    ];
    for (let i = 0; i < names.length; i++) {
        try {
            gl = canvas.getContext(names[i]);
        } catch (e) { }
        if (gl) break;
    }
    if (gl === null) {
        alert('WebGL is not available');
    } else {
        alert('Hooray! You got a WebGL context');
    }
}

getGLContext();